package whf.framework.ext.dao;

import java.util.List;

import whf.framework.entity.TreeNode;
import whf.framework.exception.FindException;
import whf.framework.ext.entity.MenuItem;
import whf.framework.log.Log;
import whf.framework.log.LogFactory;
import whf.framework.util.StringUtils;

/**
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2006-06-07
 */
public class MenuItemDAOImp extends whf.framework.dao.DAOImp<MenuItem> implements MenuItemDAO {
	private static Log log = LogFactory.getLog(MenuItemDAOImp.class);
	
	public List<MenuItem> findChildren(TreeNode parent, String queryString){
		List<MenuItem> list = null;
		StringBuilder sb = new StringBuilder();
		try{
			if(parent == null){
				sb.append(" where t.parent is null ");
				if(!StringUtils.isEmpty(queryString)){
					sb.append(" and ").append(queryString);
				}
				list = super.find(sb.toString());
			}else{
				sb.append(" where t.parent = ?");
				if(!StringUtils.isEmpty(queryString)){
					sb.append(" and ").append(queryString);
				}
				list = super.find(sb.toString(), parent);
			}
		}catch(FindException e){
			log.error(this, e);
		}
		return list;
	}
} 